﻿@typeparam T where T: Enum

<div class="mud-width-full d-flex justify-end">
    <MudButtonGroup OverrideStyles="false">
        @foreach (int value in Enum.GetValues(Type))
        {
            <MudButton Color="Color.Primary" Size="Size.Small" DisableElevation="true" Variant="@(value == Convert.ToInt32(Value) ? Variant.Filled : Variant.Outlined)" OnClick="() => Value = (T)Enum.ToObject(Type, value)">@Enum.GetName(Type, value)</MudButton>
        }
    </MudButtonGroup>
</div>

@code {
    private T _value;

    [Parameter]
    public T Value
    {
        get => _value;
        set
        {
            if (_value.Equals(value)) return;
            _value = value;
            ValueChanged.InvokeAsync(value);
        }
    }

    [Parameter] public EventCallback<T> ValueChanged { get; set; }

    [Parameter] public Color Color { get; set; }

    private Type Type => typeof(T);
}
